#include "../kernel.h"

void ipi_handler(struct trapframe_t tf)
{
	 int result = 0;
	 int lcpu = cur_lcpu();
	 if (lcpus[lcpu].ipi_recv_lock == 0) return;
	 if (lcpus[lcpu].ipi_func == IPI_IDLE) goto ipi_finish;

	 switch (lcpus[lcpu].ipi_func)
	 {
	 case IPI_INVOKE:
	 {
		  /* TODO */
		  break;
	 }
	 case IPI_INVOKE_ALL:
	 {
		  /* TODO */
		  break;
	 }
	 }

ipi_finish:
	 lcpus[lcpu].ipi_func = IPI_IDLE;
	 
	 spl_release(&lcpus[lcpu].ipi_recv_lock);
	 spl_release(&lcpus[lcpus[lcpu].ipi_source].ipi_send_lock);

	 /* ??? to fix? */
	 if (result == -E_YIELD)
	 {
		  call_yield();
	 }
}
